home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9767 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  63 lines

  1. Path: lrz-muenchen.de!news
  2. From: ua302aa@lrz-muenchen.de ()
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! Modifying the EOF in a file!
  5. Date: 13 Mar 1996 06:18:12 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4i5pb4$fae@sparcserver.lrz-muenchen.de>
  9. References: <4i585k$4ia@news.netam.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. bgc@alpha.netam.net (The Bowling Green Connection) writes:
  13.  
  14. >I am having trouble shortening the size of a text file...
  15. >Suppose I have a text file with 3 lines of data, then I
  16. >run this program:
  17.  
  18. >void main() {
  19.  
  20. Next to no comment :-)
  21.  
  22. >   FILE *dat;
  23. >   dat=fopen("file.txt", "r+");
  24.  
  25. I fail to see where you want to _write_ to "file.txt"
  26.  
  27. >   fprintf(dat, "Hello! %c", EOF);
  28.  
  29. EOF cannot be a char, so printing it as a char might be a
  30. bad idea.
  31.  
  32. >   fclose(dat);
  33. >}
  34.  
  35. Well, whatever your program does ... it is right doing so because
  36. it's behavior is undefined.
  37.  
  38. Something as simple as
  39.  
  40.    #include <stdio.h>
  41.  
  42.    int main() {
  43.       FILE *dat = fopen("file.txt", "w"); 
  44.       if (dat) {
  45.          fputs("Hello! ", dat);
  46.          fclose(dat);
  47.       }
  48.       return 0;
  49.    }
  50.  
  51. should do what you want.
  52.  
  53. >Why doesn't the EOF character chop off the remaining two lines?
  54.  
  55. Since a file can be seen as a sequence of char, and since EOF is
  56. _not_ a char, who knows. 
  57.  
  58. Kurt
  59. --
  60. | Kurt Watzka                             Phone : +49-89-2180-6254
  61. | watzka@stat.uni-muenchen.de
  62. | ua302aa@sunmail.lrz-muenchen.de
  63.